package com.luyou.framework.common.exception;

import com.luyou.framework.common.constants.DefaultErrorCodeEnum;
import com.luyou.framework.common.constants.ErrorCode;

public class DefaultException extends RuntimeException{

    private final ErrorCode errorCode;

    private String msg;

    private String tips;
    /**
     * 文本替换的参数
     */
    private Object[] args;

    public DefaultException(ErrorCode errorCode, String tips, String... args) {
        this.errorCode = errorCode;
        this.tips = tips;
        this.args = args;
    }

    public DefaultException(ErrorCode errorCode, String... args) {
        this.errorCode = errorCode;
        this.args = args;
    }

    public DefaultException(Throwable cause) {
        this.errorCode = DefaultErrorCodeEnum.ERROR;
    }

    public String getMsg() {
        return msg;
    }

    public ErrorCode getErrorCode() {
        return this.errorCode;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }

    public Object[] getArgs() {
        return args;
    }

    @Override
    public String getMessage() {
        return super.getMessage() == null ? null : String.format(super.getMessage(), args);
    }
}
